﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPFOpenVideo.Linq;
using WPFOpenVideo.Model;
using System.Xml.Linq;
using System.Xml;

namespace WPFOpenVideo.Bll
{
    public partial class AddPointForButtonBll
    {
        private XmlLinq new_XmlLinq = new XmlLinq();
        private TaskFactory new_TaskFactory = new TaskFactory();

        /// <summary>
        /// 返回XML文件中的数据节点集
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        //public List<AddPointForButtonModel> ReadXmlBll(string path,Action callback_loadUI)
        //{
        //    List<AddPointForButtonModel> list = new List<AddPointForButtonModel>();

        //    IEnumerable<XElement> xele = new_XmlLinq.ReadXmlLinq(path);
        //    foreach (var item in xele)
        //    {
        //        list.Add(new AddPointForButtonModel()
        //        {
        //            Id = Convert.ToInt32(item.Attribute("Id").Value),
        //            PlcField = item.Element("PlcField").Value,
        //            VideoSource = item.Element("VideoSource").Value,
        //            VideoName = item.Element("VideoName").Value
        //        });
        //    }
        //    return list;
        //}


        public void ReadXmlAsynBll(string path, Action<List<XElement>> callback_loadUI)
        {
            new_TaskFactory.StartNew(() =>
            {
                new_XmlLinq.StreamReadXmlLinq(path, callback_loadUI);
            });
        }




        public bool DeleteXmlBll(string path,string tag)
        {
           return new_XmlLinq.DeleteXmlLinq(path, tag);
        }


        public void UpdateXmlBll(string path,string tag,AddPointForButtonModel add_point_for_button_model)
        {
            new_XmlLinq.UpdateXmlLinq(path, tag, add_point_for_button_model);
        }

        public void InsertXmlBll(string path,AddPointForButtonModel add_point_for_button_model)
        {
            new_XmlLinq.InsertXmlLinq(path, add_point_for_button_model);
        }


        //public List<AddPointForButtonModel> ReadXmlAsynBll(string path,Action action)
        //{
        //    List<AddPointForButtonModel> tmp_list = new List<AddPointForButtonModel>();
        //    new_TaskFactory.StartNew(() => {tmp_list= ReadXmlBll(path, action); });
        //    return tmp_list;
        //}

        public bool DeleteXmlAsynBll(string path, string tag)
        {
            bool b = false;
            new_TaskFactory.StartNew(() => { b = DeleteXmlBll(path, tag); });
            return b;
        }

        public void UpdateXmlAsynBll(string path, string tag, AddPointForButtonModel add_point_for_button_model)
        {
            new_TaskFactory.StartNew(() => { UpdateXmlBll(path, tag, add_point_for_button_model); });
        }

        public void InsertXmAsynlBll(string path, AddPointForButtonModel add_point_for_button_model)
        {
            new_TaskFactory.StartNew(() => { InsertXmlBll(path, add_point_for_button_model); });
        }
    }
}
